<style scoped lang="less">
.lyricBox {
  margin-top: 10px;
  width: 100%;
  height: 400px;
  transition: all ease-in-out .3s;
  box-sizing: border-box;
  padding: 10px 0;
  position: relative;
  overflow: hidden;
  &-round{
    position: relative;
    &::after{
      position: absolute;
      bottom: 0;
      left: 0;
      content: '';
      background: linear-gradient(to bottom, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.5),rgba(255, 255, 255, 0.7),rgba(255, 255, 255, 1));
      width: 100%;
      height: 8px;
      z-index: 1;
    }
    &::before{
      position: absolute;
      top: 0;
      left: 0;
      content: '';
      background: linear-gradient(to top, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.5),rgba(255, 255, 255, 0.7),rgba(255, 255, 255, 1));
      width: 100%;
      height: 8px;
      z-index: 1;
    }
  }
  &__row{
    transition: all ease-in-out .3s;
    font-size: 14px;
    line-height: 30px;
    font-weight: 400;
    color: rgba(153, 153, 153, 0.92);
    white-space: pre-wrap;
  }
  &__active{
    font-size: 16px;
    color: #141B27;
    font-weight: 500;
  }
}
</style>
<template>
  <div class="lyricBox-round">
    <div class="lyricBox" ref="lyricBox">
      <div class="lyricBox__row" ref="lyricBoxRow" v-for="(ele,index) of list" :class="{'lyricBox__active':activeIndex === index}">
        {{ ele.value }}
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
// 资源
import netEasyMusicStore from '../../store'
import {computed, ref, watch} from "vue";
import {getDomPosition} from "@/helper";

const lyricBox = ref(null)
const lyricBoxRow = ref(null)
const list = computed(() => (netEasyMusicStore.$state.setting?.lyric.list))
const activeIndex =  computed(() => (netEasyMusicStore.$state.setting?.lyric.now))

watch(activeIndex,value => {
  const {height} = getDomPosition(lyricBoxRow.value?.[0]) ?? { height: 0 }
  const { height:midHeight } = getDomPosition(lyricBox.value) ?? { height: 0 }
  lyricBox.value.scrollTop = height * value - (midHeight / 3)
})
</script>

